package com.situ.springboot.pattern;

import java.io.Serializable;

// 懒汉式单例 - 内部类
public class Singleton5 implements Serializable {
    private Singleton5() {
        System.out.println("private Singleton5()");
    }

    private static class Holder {
        // 会放到静态代码块中执行，静态代码块里面的线程安全由虚拟机来保证
        static Singleton5 INSTANCE = new Singleton5();
    }

    // 懒汉式，不调用getInstance时候不会触发Holder的加载和初始化
    public static Singleton5 getInstance() {
        return Holder.INSTANCE;
    }

    public static void staticMethod() {
        System.out.println("staticMethod()");
    }
}
